<?php
//首页
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {

    //列表页
    public function index(){
    	$id = I('get.cateid',1,'intval');
        $Article = M('Article')->where(array('cateid'=>$id,'status'=>'1'))->order('sort asc,id desc')->select();
        foreach ($Article as &$v) {
        	$v['d']  = date("d",$v['time']);
        	$v['ym'] = date("Ym",$v['time']);
        	$v['yu'] = ($v['id'] + 10 ) % 5;
        }
        $info = M('System')->where(array('id'=>'1'))->find();

        $cate = M('Cate')->where(array('status'=>'1'))->select();
// print_r($cate);die();

        $this->assign('info',$info);
        $this->assign('list',$Article);
        $this->assign('cate',$cate);

        $this->display();
    }

    //文章内容页
    public function content(){
    	$id = I('get.id',1,'intval');
    	$cateid = I('get.cateid','','intval');
    	$info = M('Article')->where(array('id'=>$id,'cateid'=>$cateid))->find();
    	$info['time'] = date('Y/m/d H:i',$info['time']);
    	// 文章点击量的实现，借助于setInc()函数，每访问一次新闻字段'click'加1
        M('Article')->where(array('id'=>$id))->setInc('click',1);
// print_r($info);die();
    	$web = M('System')->where(array('id'=>'1'))->getField('title');

    	$this->assign('web',$web);
    	$this->assign('info',$info);
    	$this->display();
    }

}